package chapter03;

import com.sun.media.sound.SoftTuning;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Locale;

public class RequestTest implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;
        PrintWriter writer = response.getWriter();


        String pathInfo = request.getPathInfo();
        String pathTranslated = request.getPathTranslated();
        String realPath = request.getRealPath("/");
        String servletPath = request.getServletPath();
        String serverName = request.getServerName();
        int serverPort = request.getServerPort();
        String scheme = request.getScheme();
        String protocol = request.getProtocol();
        String remoteHost = request.getRemoteHost();
        String remoteAddr = request.getRemoteAddr();
        String remoteUser = request.getRemoteUser();
        String path = request.getContextPath();
        String requestURI = request.getRequestURI();

        writer.println("pathInfo:" + pathInfo);
        writer.println("pathTranslated:" + pathTranslated);
        writer.println("servletPath:" + servletPath);
        writer.println("realPath:" + realPath);
        writer.println("serverName:" + serverName);
        writer.println("serverPort:" + serverPort);
        writer.println("scheme:" + scheme);
        writer.println("protocol:" + protocol);
        writer.println("remoteHost:" + remoteHost);
        writer.println("remoteAddr:" + remoteAddr);
        writer.println("remoteUser:" + remoteUser);
        writer.println("contextPath:" + path);
        writer.println("requestURI:" + requestURI);

        System.out.println("pathInfo:" + pathInfo);
        System.out.println("pathTranslated:" + pathTranslated);
        System.out.println("servletPath:" + servletPath);
        System.out.println("realPath:" + realPath);
        System.out.println("contextPath:" + path);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
